package com.example.demo.utils;

import com.example.demo.dto.UserDTO;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.security.core.userdetails.User;


import java.util.List;


public class SecurityUtil {
    public static void securityLogin(String username,String role ){
//        System.out.println("============\n登录用户权限设置:\n"+"用户角色:ROLE_ACTIVITI_"+role.toUpperCase()+"\n用户组:GROUP_"+role+"\n==============");
        List<GrantedAuthority> authorities= AuthorityUtils.createAuthorityList("ROLE_ACTIVITI_USER","GROUP_"+role);
        User user=new User(username,"",authorities);
        SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(user,null,authorities));
        org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(username);
    }
}
